package com.ytc.teaching.controller;


import com.ytc.commons.model.dto.MediaQueryDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.dto.WorkDto;
import com.ytc.commons.model.vo.MediaVo;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.commons.model.vo.WorkVo;
import com.ytc.commons.utils.BeanHelper;
import com.ytc.teaching.domain.Work;
import com.ytc.teaching.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/work")
public class WorkController {

    @Autowired
    private WorkService workService;
    //分页查询课程计划作业列表
    @PostMapping("/list")
    public ResponseResult workList(PageRequest request,@RequestBody WorkDto dto){
        return workService.workList(request,dto);
    }

    //新增或者修改试卷
    @PostMapping
    public ResponseResult saveWord(@RequestBody WorkDto dto){
        return workService.saveWork(dto);
    }
    //删除试卷
    @DeleteMapping("/{workId}")
    public ResponseResult deleteByWorkId(@PathVariable("workId") Long workId){
         return  workService.deleteByWorkId(workId);
    }

    //根据ID查询作业
    @GetMapping("/{workId}")
    public ResponseResult findByWorkId(@PathVariable("workId") Long workId){
        Work work = workService.getById(workId);
        WorkVo workVo = BeanHelper.copyProperties(work, WorkVo.class);
        return ResponseResult.okResult(workVo);
    }
}
